package com.xiaohudie.SGGio;

import lombok.SneakyThrows;

import java.io.*;

/**
 * @Author xiao hu die
 * @Date 2022/3/25 14:44
 * @Version 1.0
 */
public class InputStreamReaderTest  {
 public static void main(String[] args) throws Exception {
 //test01();
  test02();
 }
 @SneakyThrows
 public static void test01(){
  FileInputStream fileInputStream = new FileInputStream("D:\\\\java图片代码\\\\22.txt");
  InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
  char[] chars =new char[20];
  int len;
  while ((len =inputStreamReader.read(chars))!=-1){
   String str =new String(chars,0,len);
   System.out.println(str);
  }
  inputStreamReader.close();
 }
 public static void test02() throws IOException {
  FileInputStream fileInputStream = new FileInputStream("D:\\\\java图片代码\\\\22.txt");
  FileOutputStream fileOutputStream = new FileOutputStream("D:\\\\java图片代码\\\\22GBK.txt");
  InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream,"utf-8");
  OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream,"utf-16");
  char[] chars =new char[20];
  int len;
  while ((len = inputStreamReader.read(chars))!=-1){
   outputStreamWriter.write(chars,0,len);
  }
  inputStreamReader.close();
  outputStreamWriter.close();
 }
}
